﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.guide.ui {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import com.greensock.*;
    import flash.text.*;
    import org.aswing.event.*;
    import org.aswing.border.*;
    import Modules.guide.*;
    import Display.aswingui.*;

    public class WelcomeDialog extends GenericDialog {

        protected const AVATAR_DIALOG_OFFSET_X:int = 20;
        protected const AVATAR_DIALOG_OFFSET_Y:int = 10;
        protected const DIALOG_OFFSET_Y:int = 50;

        protected var m_welcomeBG:DisplayObject;
        protected var m_welcomeInnerBG:DisplayObject;
        protected var m_hintInnerBG:DisplayObject;
        protected var m_cityHeader:DisplayObject;
        protected var m_advisor:DisplayObject;
        protected var m_avatarWindow:JWindow;
        protected var m_assetsLoaded:int = 0;
        protected var m_avatarURL:String;
        protected var m_hintMessage:String;
        protected var m_avatarContent:DisplayObject;
        protected var m_bgContentLoader:Loader;
        public var m_loaderObj:DisplayObject;
        protected var m_speech:DisplayObject;
        protected var m_button:CustomButton;

        public function WelcomeDialog(_arg1:String, _arg2:String="", _arg3:int=0, _arg4:Function=null, _arg5:Boolean=true, _arg6:String="", _arg7:String="", _arg8:Function=null){
            this.m_avatarURL = _arg6;
            this.m_hintMessage = _arg7;
            super(_arg1, _arg2, _arg3, _arg4, _arg2, "", _arg5, 0, "", _arg8);
        }
        override protected function loadAssets():void{
            var _local1:String = Global.getAssetURL(this.m_avatarURL);
            Global.delayedAssets.get(this.m_avatarURL, this.makeAssets);
            Global.delayedAssets.get(GuideUtils.TUTORIAL_ASSETS, this.makeAssets);
        }
        override public function isLockable():Boolean{
            return (false);
        }
        override protected function makeAssets(_arg1:DisplayObject, _arg2:String):void{
            switch (_arg2){
                case GuideUtils.TUTORIAL_ASSETS:
                    this.m_loaderObj = _arg1;
                    break;
                case this.m_avatarURL:
                    this.m_avatarContent = _arg1;
                    break;
            };
            this.m_assetsLoaded++;
            if (this.m_assetsLoaded < 2){
                return;
            };
            m_loaded = true;
            this.onAssetsLoaded();
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            var _local8:AssetPane;
            var _local2:Object = this.m_loaderObj;
            this.m_advisor = this.m_avatarContent;
            this.m_speech = (new _local2.speechBubbleLeft() as DisplayObject);
            m_jpanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            _local3.setBackgroundDecorator(new MarginBackground(this.m_speech, new Insets(0, 0, 10, 0)));
            var _local5:int = this.getTfWidth(m_message, m_dialogTitle);
            if (m_dialogTitle){
                _local8 = ASwingHelper.makeMultilineCapsText(m_dialogTitle, (_local5 + 20), EmbeddedArt.TITLE_FONT, TextFormatAlign.LEFT, 16, EmbeddedArt.darkBlueTextColor, null, true);
                _local4.append(_local8);
            };
            var _local6:AssetPane = ASwingHelper.makeMultilineText(m_message, _local5, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 16, EmbeddedArt.brownTextColor, null, true);
            _local4.appendAll(_local6, ASwingHelper.verticalStrut(10));
            _local4.setBorder(new EmptyBorder(null, new Insets(10, 50, 0, 25)));
            var _local7:JPanel = this.createButtonPanel();
            _local4.append(_local7);
            _local3.append(_local4);
            ASwingHelper.prepare(_local3);
            m_jpanel.append(_local3);
            this.finalizeAndShow();
        }
        protected function getTfWidth(_arg1:String, _arg2:String):int{
            return (Math.max(200, (_arg1.length * 1.5), (_arg2.length * 1.5)));
        }
        protected function createButtonPanel():JPanel{
            this.m_button = new CustomButton(ZLoc.t("Dialogs", "OkButton"), null, "GreenButtonUI");
            this.m_button.addActionListener(this.onPanelClick, 0, true);
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local1.append(this.m_button);
            return (_local1);
        }
        override protected function showTween():void{
            this.mouseEnabled = false;
            this.mouseChildren = false;
            var _local1:Point = new Point(m_content.width, m_content.height);
            var _local2:Matrix = new Matrix();
            _local2.scale(1, 1);
            m_content.transform.matrix = _local2;
            TweenLite.from(this, 0.25, {
                alpha:0,
                onComplete:onShowComplete
            });
        }
        override protected function hideTween(_arg1:Function):void{
            this.mouseEnabled = false;
            this.mouseChildren = false;
            if (_arg1 != null){
                TweenLite.to(this, 0.25, {
                    alpha:0,
                    onComplete:_arg1
                });
            } else {
                TweenLite.to(this, 0.25, {alpha:0});
            };
        }
        override protected function finalizeAndShow():void{
            ASwingHelper.prepare(m_jpanel);
            m_jwindow.setContentPane(m_jpanel);
            ASwingHelper.prepare(m_jwindow);
            m_jwindow.show();
            var _local1:Sprite = new Sprite();
            this.addChild(_local1);
            this.m_avatarWindow = new JWindow(_local1);
            if (((((this.m_advisor.parent) && ((this.m_advisor.parent is Sprite)))) && ((this.m_advisor is Bitmap)))){
                this.m_advisor = new Bitmap((this.m_advisor as Bitmap).bitmapData);
            };
            var _local2:AssetPane = new AssetPane(this.m_advisor);
            this.m_avatarWindow.setContentPane(_local2);
            ASwingHelper.prepare(this.m_avatarWindow);
            this.m_avatarWindow.show();
            var _local3:int = ((this.m_avatarWindow.width - this.AVATAR_DIALOG_OFFSET_X) + m_jwindow.width);
            var _local4:Point = new Point(((Global.stage.stageWidth / 2) - (_local3 / 2)), ((Global.stage.stageHeight / 2) - (m_jwindow.height / 2)));
            m_jwindow.setX(((_local4.x + this.AVATAR_DIALOG_OFFSET_X) + this.m_avatarWindow.getWidth()));
            m_jwindow.setY((_local4.y - this.DIALOG_OFFSET_Y));
            this.m_avatarWindow.setX((_local4.x + this.AVATAR_DIALOG_OFFSET_X));
            this.m_avatarWindow.setY((_local4.y - (this.DIALOG_OFFSET_Y + this.AVATAR_DIALOG_OFFSET_Y)));
            setupDialogStatsTracking();
            onDialogInitialized();
        }
        override public function centerPopup():void{
            var _local1:int = ((this.m_avatarWindow.width - this.AVATAR_DIALOG_OFFSET_X) + m_jwindow.width);
            var _local2:Point = new Point(((Global.stage.stageWidth / 2) - (_local1 / 2)), ((Global.stage.stageHeight / 2) - (m_jwindow.height / 2)));
            m_jwindow.setX(((_local2.x + this.AVATAR_DIALOG_OFFSET_X) + this.m_avatarWindow.getWidth()));
            m_jwindow.setY((_local2.y - this.DIALOG_OFFSET_Y));
            this.m_avatarWindow.setX((_local2.x + this.AVATAR_DIALOG_OFFSET_X));
            this.m_avatarWindow.setY((_local2.y - (this.DIALOG_OFFSET_Y + this.AVATAR_DIALOG_OFFSET_Y)));
        }
        protected function onPanelClick(_arg1:AWEvent):void{
            countDialogAction("OK");
            if (m_callback != null){
                m_callback(_arg1);
            };
            this.close();
            dispatchEvent(new Event(Event.CLOSE, true));
        }

    }
}//package Modules.guide.ui 
